#include <iostream>
using namespace std;
int main ()
{int m,j,k,l;int sum=0,a;
 while(scanf("%m",&m)!=0)
 {
   //{cin>>m;
    //if(m==0)  break; 
    for(int h=1;h<=3;h++)
      {while (m==0)//for(int i=1;m==0;i++)
         {a=m%10;
          sum=sum+a;
          m=m/10;
          }
          if(sum<10) cout<<sum<<endl;
          else {m=sum;break;}
       }
  }
  system("pause");
  return 0;
}
    
      
    
   
  
      
    
      
    
